/**
 * @file led.h
 * @author chushang (email:chushangcs@163.com)
 * @brief 实现LED初始化，点亮，熄灭，翻转，闪烁
 * @version 1.2
 * @date 2025-06-04
 *
 * @copyright Copyright (c) 2025
 *
 */

#ifndef __LED_H
#define __LED_H

#define DRIVER_INCLUDE "stm32f1xx_hal.h"
#include DRIVER_INCLUDE

#define LED_MAX_NUM 2 // LED最大数量

typedef enum _LEDState
{
    LED_OFF = 0,
    LED_ON  = !LED_OFF
} LEDState;

typedef struct _LED
{
    LEDState      state;     // LED亮灭情况
    GPIO_TypeDef *gpio_port; // 引脚端口
    uint16_t      gpio_pin;  // 引脚号

    // 以下已弃用
    // void (*LightOn)(struct _LED *led);
    // void (*LightOff)(struct _LED *led);
    // void (*Twinkle)(struct _LED *led, uint16_t period_ms);
} LED;

typedef struct _LEDConfig
{
    GPIO_TypeDef *gpio_port; // 引脚端口
    uint16_t      gpio_pin;  // 引脚号

    // 以下已弃用
    // void (*LightOn)(LED *led);
    // void (*LightOff)(LED *led);
    // void (*Twinkle)(LED *led, uint16_t period_ms);
} LEDConfig;

LED *LED_Register(LEDConfig *lc);
void LED_SetState(LED *led, LEDState ls);
void LED_On(LED *led);
void LED_Off(LED *led);
void LED_Twinkle(LED *led, uint16_t period_ms);
void LED_Toggle(LED *led);
void LED_Tick(void);

#endif // !__LED_H